<!doctype html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Document</title>
  <link rel="stylesheet" href="/stylesheets/reg.css">
  <script src="/javascripts/jquery.js"></script>
  <script src="/javascripts/angular.js"></script>
  <!--<script src="/javascripts/controller.js"></script>-->
  <script src="/plugin/bootstrap/js/bootstrap.js"></script>
  <link rel="stylesheet" href="/plugin/bootstrap/css/bootstrap.css">
  <style>
    .h2{
      font-size: 28px;
      text-align: center;
      color: #CCC;
      margin: 0;
      /*line-height: 1;*/
      font-family: Microsoft Yahei;
      font-weight: bold;
      text-shadow: 1px 1px 1px rgba(0,0,0,0.5);
    }

  </style>
</head>
<body>
<main>
  <div class="logo"><a href="/"><img src="/images/logo.png" alt=""></a></div>
  <h2 class="h2">更改密码</h2>
  <h2 class="h2 yanzheng">首先请验证预留问题</h2>
  <h2 class="h2 xiugai" style="display: none;">验证成功!&nbsp;!&nbsp;请修改您的密码</h2>
  <div class="floatright" ng-app="user_changePassword">
    <div class="regBoard" ng-controller="userchangePassword">
      <form class="form yanzhengform" name="changePasswordForm" ng-submit="processchangePasswordForm(changePasswordForm.$valid)" novalidate>
        <h2><small class="text-danger hide" id="errorInfo">验证预留问题错误,请重新输入</small></h2>
        <div class="form-group">
          <label>真实姓名</label>
          <input type="text" name="userPasswordOne" id="userPasswordOne" class="form-control" ng-minlength="2" placeholder="请输入答案" ng-model="changePasswordForm.PasswordOne" required>
          <label style="display:inline-block;width: 250px;font-size: 15px;" ng-cloak for="inputError"
                 class="control-label text-danger"
                 ng-show="changePasswordForm.userPasswordOne.$invalid && !changePasswordForm.userPasswordOne.$pristine"><i
                    class="glyphicon glyphicon-info-sign"></i>至少两个文字</label>
        </div>
        <div class="form-group">
          <label>就读学校</label>
          <input type="text" name="userPasswordTwo" id="userPasswordTwo" class="form-control" ng-minlength="2"  placeholder="请输入答案" ng-model="changePasswordForm.PasswordTwo" required>
          <label style="display:inline-block;width: 250px;font-size: 15px;" ng-cloak for="inputError"
                 class="control-label text-danger"
                 ng-show="changePasswordForm.userPasswordTwo.$invalid && !changePasswordForm.userPasswordTwo.$pristine"><i
                    class="glyphicon glyphicon-info-sign"></i>至少两个文字</label>
        </div>
        <div class="form-group">
          <label>所在年级</label>
          <input type="text" name="userPasswordThree" id="userPasswordThree" class="form-control" ng-minlength="1" placeholder="请输入答案" ng-model="changePasswordForm.PasswordThree" required>
          <label style="display:inline-block;width: 250px;font-size: 15px;" ng-cloak for="inputError"
                 class="control-label text-danger"
                 ng-show="changePasswordForm.userPasswordThree.$invalid && !changePasswordForm.userPasswordThree.$pristine"><i
                    class="glyphicon glyphicon-info-sign"></i>至少一个文字</label>
        </div>
        <button role="button" ng-disabled="changePasswordForm.$invalid" class="btn btn-primary" id="button">确定验证</button>
        <button style="margin: 30px 0 30px 0" class="btn quxiao" id="button">取消验证</button>
      </form>

      <form style="display: none;" class="form xiugaiform" name="xiugaiPasswordForm" ng-submit="processXiugaiPasswordForm(xiugaiPasswordForm.$valid)" novalidate>
        <h2><small class="text-danger hide" id="errorInfoTwo">修改失败,GG~</small></h2>
        <div class="form-group">
          <label>密码</label>
          <input type="password" class="form-control" id="password" name="password" placeholder="请输入密码"
                 ng-pattern="/(?!^\\d+$)(?!^[a-zA-Z]+$)(?!^[_#@]+$).{5,}/" ng-maxlength="12"
                 ng-model="xiugaiPasswordFormData.password" required/>
          <label style="display:inline-block;width: 250px;font-size: 15px;" ng-cloak for="inputError"
                 class="control-label text-danger"
                 ng-show="xiugaiPasswordForm.password.$invalid && !xiugaiPasswordForm.password.$pristine"><i
                    class="glyphicon glyphicon-info-sign"></i> 6-12位，只能包含字母、数字和下划线</label>
        </div>
        <div class="form-group">
          <label>确认密码</label>
          <input type="password"
                 class="form-control"
                 pw-check="password" name="confirmPassword" id="confirmPassword" placeholder="请再次输入密码"
                 ng-model="xiugaiPasswordFormData.confirmPassword"
                 ng-pattern="/(?!^\\d+$)(?!^[a-zA-Z]+$)(?!^[_#@]+$).{5,}/"
                 ng-maxlength="12" required/>
          <label style="display:inline-block;width: 250px;font-size: 15px;" ng-cloak for="inputError"
                 class="control-label text-danger"
                 ng-show="xiugaiPasswordForm.confirmPassword.$invalid && !xiugaiPasswordForm.confirmPassword.$pristine"><i
                    class="glyphicon glyphicon-info-sign"></i> 两次输入的密码不匹配</label>
        </div>
        <button role="button" ng-disabled="xiugaiPasswordForm.$invalid" class="btn btn-primary" id="button">确定修改</button>
        <button style="margin: 30px 0 30px 0" class="btn quxiaoxiugai" id="button">取消修改</button>
      </form>

    </div>
  </div>
</main>
</body>
</html>
<script>
  var user_changePassword = angular.module('user_changePassword',[]);
  user_changePassword.controller("userchangePassword",function($scope,$http){
    $scope.email = "<%= user.email %>";
    $http.get('/userchangpassword?uid=' + $scope.email)
            .success(function (result) {
              $scope.user = result;
            })
    $scope.processchangePasswordForm = function(isVaild){
      if(isVaild){
        if($scope.user.userPasswordOne == $scope.changePasswordForm.PasswordOne && $scope.user.userPasswordTwo == $scope.changePasswordForm.PasswordTwo && $scope.user.userPasswordThree == $scope.changePasswordForm.PasswordThree){
//          alert('验证成功,请修改密码')
          $('.yanzheng').css("display","none");
          $('.yanzhengform').css("display","none");
          $('.xiugai').css("display","block");
          $('.xiugaiform').css("display","block");


        }else {
          $('#errorInfo').removeClass('hide').text(data)

        }
      }
    }
    $scope.processXiugaiPasswordForm = function(isVaild){
      if(isVaild){
        $http({
          method:'POST',
          url:'/doChangpassword',
          data: $.param($scope.xiugaiPasswordFormData),
          headers:{'Content-Type':'application/x-www-form-urlencoded'}
        }).success(function(data){
          if (data === "success") {
            alert('恭喜您,修改成功,请妥善保存呦~');

            window.location = "<%= regBack %>";
          } else {
            $('#errorInfoTwo').removeClass('hide').text(data)
//            alert('修改失败,GG~')
          }
        })
      }
    }

  })

  var back = document.querySelector('.quxiao');
  back.onclick = function () {
    window.location = "<%= regBack %>";
  }
  var backxiugai = document.querySelector('.quxiaoxiugai');
  backxiugai.onclick = function () {
    window.location = "<%= regBack %>";
  }
</script>





